import axios from "axios";
import config from '@/config'
import {useUser} from '@/stores/user'

const instance = axios.create({
    baseURL: config.baseURL
  })
  
  instance.interceptors.request.use(config => {
    const userStore = useUser()  
    const params = {
      client_id:1,
      token:userStore.token
    }   
    config.data=Object.assign(config.data,params)
    return config
  }, error => {
    return Promise.resolve(error);
  })
  
  instance.interceptors.response.use(res => {
    return res
  }, error => {
    return Promise.resolve(error)
  })
  
  const request = (options)=>{
      return instance.request(options).then(res=>{
        return res.data.data
      })
  }
  
  export default request;